<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Title</title></head><body><div class="cl-preview-section"><h2 id="目录">目录</h2>
</div><div class="cl-preview-section"><ul>
<li>添加启动图（可选）</li>
<li>添加APP名和快照名
<ul>
<li>AndroidManifest.xml</li>
<li>main.dart</li>
</ul>
</li>
<li>检查和配置build.gradle文件
<ul>
<li>applicationId</li>
<li>versionCode &amp; versionName:</li>
<li>minSdkVersion &amp; targetSdkVersion</li>
</ul>
</li>
<li>添加APP启动图标</li>
<li>添加网络访问权限
<ul>
<li>在<code>AndroidManifest.xml</code>中添加<code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt;</code></li>
</ul>
</li>
<li>签名APP</li>
<li>构建一个release包</li>
<li>发布到Android各大应用市场
<ul>
<li><a href="https://app.baidu.com/apps/">https://app.baidu.com/apps/</a></li>
</ul>
</li>
</ul>
</div><div class="cl-preview-section"><h2 id="添加启动屏">添加启动屏</h2>
</div><div class="cl-preview-section"><h3 id="添加启动背景图">添加启动背景图</h3>
</div><div class="cl-preview-section"><blockquote>
<p><code>drawable-v21\launch_background.xml</code>与<code>drawable\launch_background.xml</code></p>
</blockquote>
</div><div class="cl-preview-section"><pre class="  language-xml"><code class="prism  language-xml"><span class="token prolog">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>layer-list</span> <span class="token attr-name"><span class="token namespace">xmlns:</span>android</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>http://schemas.android.com/apk/res/android<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
+    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>item</span> <span class="token attr-name"><span class="token namespace">android:</span>drawable</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@drawable/splash_screen_background<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>layer-list</span><span class="token punctuation">&gt;</span></span>
</code></pre>
</div><div class="cl-preview-section"><h3 id="设置启动屏全屏">设置启动屏全屏</h3>
</div><div class="cl-preview-section"><blockquote>
<p><code>styles.xml</code></p>
</blockquote>
</div><div class="cl-preview-section"><pre class="  language-xml"><code class="prism  language-xml">    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>LaunchTheme<span class="token punctuation">"</span></span> <span class="token attr-name">parent</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@android:style/Theme.Light.NoTitleBar<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span class="token style language-css">
        &lt;item name=<span class="token string">"android:windowBackground"</span>&gt;@drawable/launch_background&lt;/item&gt;
   +     &lt;item name=<span class="token string">"android:windowFullscreen"</span>&gt;true&lt;/item&gt;
    </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
</code></pre>
</div><div class="cl-preview-section"><h3 id="支持刘海屏">支持刘海屏</h3>
</div><div class="cl-preview-section"><blockquote>
<p><code>AndroidManifest.xml</code></p>
</blockquote>
</div><div class="cl-preview-section"><pre class="  language-xml"><code class="prism  language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>activity</span>
            <span class="token attr-name"><span class="token namespace">android:</span>name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>.MainActivity<span class="token punctuation">"</span></span>
            <span class="token attr-name"><span class="token namespace">android:</span>launchMode</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>singleTop<span class="token punctuation">"</span></span>
            <span class="token attr-name"><span class="token namespace">android:</span>theme</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@style/LaunchTheme<span class="token punctuation">"</span></span>
            <span class="token attr-name"><span class="token namespace">android:</span>configChanges</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode<span class="token punctuation">"</span></span>
            <span class="token attr-name"><span class="token namespace">android:</span>hardwareAccelerated</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>true<span class="token punctuation">"</span></span>
            <span class="token attr-name"><span class="token namespace">android:</span>windowSoftInputMode</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>adjustResize<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token comment">&lt;!-- 支持刘海屏--&gt;</span>
+            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>meta-data</span> <span class="token attr-name"><span class="token namespace">android:</span>name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>android.notch_support<span class="token punctuation">"</span></span>  <span class="token attr-name"><span class="token namespace">android:</span>value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>true<span class="token punctuation">"</span></span><span class="token punctuation">/&gt;</span></span>
</code></pre>
</div><div class="cl-preview-section"><h3 id="设置状态栏为透明色">设置状态栏为透明色</h3>
</div><div class="cl-preview-section"><pre class="  language-kotlin">
   <div>
       这里是在 src-main-kotlin-com-...-MainActivity 里面 把+去掉其它复制进去就行了
   </div>

<span class="token operator">+</span> <span class="token keyword">import</span> android<span class="token punctuation">.</span>graphics<span class="token punctuation">.</span>Color
<span class="token operator">+</span> <span class="token keyword">import</span> android<span class="token punctuation">.</span>os<span class="token punctuation">.</span>Build
<span class="token operator">+</span> <span class="token keyword">import</span> android<span class="token punctuation">.</span>os<span class="token punctuation">.</span>Bundle
<span class="token keyword">import</span> io<span class="token punctuation">.</span>flutter<span class="token punctuation">.</span>embedding<span class="token punctuation">.</span>android<span class="token punctuation">.</span>FlutterActivity

<span class="token keyword">class</span> MainActivity <span class="token operator">:</span> <span class="token function">FlutterActivity</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token operator">+</span>     <span class="token keyword">override</span> <span class="token keyword">fun</span> <span class="token function">onCreate</span><span class="token punctuation">(</span>savedInstanceState<span class="token operator">:</span> Bundle<span class="token operator">?</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token operator">+</span>         <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">onCreate</span><span class="token punctuation">(</span>savedInstanceState<span class="token punctuation">)</span>
<span class="token operator">+</span>         <span class="token keyword">if</span> <span class="token punctuation">(</span>Build<span class="token punctuation">.</span>VERSION<span class="token punctuation">.</span>SDK_INT <span class="token operator">&gt;=</span> Build<span class="token punctuation">.</span>VERSION_CODES<span class="token punctuation">.</span>LOLLIPOP<span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token operator">+</span>             <span class="token keyword">val</span> window <span class="token operator">=</span> activity<span class="token punctuation">.</span>window
<span class="token operator">+</span>             <span class="token comment">//设置状态栏为透明色，fix 启动时状态栏会灰色闪一下</span>
<span class="token operator">+</span>             window<span class="token punctuation">.</span>statusBarColor <span class="token operator">=</span> Color<span class="token punctuation">.</span>TRANSPARENT
<span class="token operator">+</span>         <span class="token punctuation">}</span>
<span class="token operator">+</span>     <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
</div><div class="cl-preview-section"><h2 id="签名app">签名APP</h2>
</div><div class="cl-preview-section"><p>构建release包需要用到keystore，如果你还没有keystore可以通过一下方式来创建：</p>
</div><div class="cl-preview-section"><h3 id="创建keystore">创建keystore</h3>
</div><div class="cl-preview-section"><blockquote>
<p>Mac：</p>
</blockquote>
</div><div class="cl-preview-section"><pre><code>keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
</code></pre>
</div><div class="cl-preview-section"><blockquote>
<p>Windows：</p>
</blockquote>
</div><div class="cl-preview-section"><pre><code>keytool -genkey -v -keystore c:\Users\USER_NAME\key.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias key
</code></pre>
</div><div class="cl-preview-section"><ul>
<li>-keystore：用户指定存储路径</li>
</ul>
</div><div class="cl-preview-section"><p>然后按照提示进行输入，完成所有输入之后会在上述路径中创建一个<code>key.jks</code>文件。然后将该文件复制到Flutter项目下的android目录下。</p>
</div><div class="cl-preview-section"><h3 id="配置keystore">配置keystore</h3>
</div><div class="cl-preview-section"><p>在<code>你的flutter应用/android</code>目录下创建<code>key.properties</code>文件，然后添加：</p>
</div><div class="cl-preview-section"><pre><code>storePassword=&lt;password from previous step&gt;
keyPassword=&lt;password from previous step&gt;
keyAlias=key
storeFile=../key.jks
</code></pre>
</div><div class="cl-preview-section"><h3 id="配置打包签名">配置打包签名</h3>
</div><div class="cl-preview-section"><p>用AS打开<code>你的flutter应用/android/app/build.gradle</code>文件然后在<code>android</code>代码块上面添加：</p>
</div><div class="cl-preview-section"><pre><code>   def keystoreProperties = new Properties()
   def keystorePropertiesFile = rootProject.file('key.properties')
   if (keystorePropertiesFile.exists()) {
       keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
   }

   android {
         ...
   }
</code></pre>
</div><div class="cl-preview-section"><p>然后在<code>android</code>代码块中添加<code>signingConfigs</code>：</p>
</div><div class="cl-preview-section"><pre><code>    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
</code></pre>
</div><div class="cl-preview-section"><p>最后在<code>buildTypes</code>代码块中添加<code>release</code>配置：</p>
</div><div class="cl-preview-section"><pre><code>    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
</code></pre>
</div><div class="cl-preview-section"><h2 id="构建release包">构建release包</h2>
</div><div class="cl-preview-section"><h3 id="构建全部架构的安装包">构建全部架构的安装包</h3>
</div><div class="cl-preview-section"><pre><code>./gradlew assembleRelease
</code></pre>
</div><div class="cl-preview-section"><p>构建出来的Release包是包含所有ABI架构的。</p>
</div><div class="cl-preview-section"><h3 id="构建单一架构的安装包">构建单一架构的安装包</h3>
</div><div class="cl-preview-section"><pre><code>cd &lt;flutter应用的android目录&gt;
flutter build apk --split-per-abi
</code></pre>
</div><div class="cl-preview-section"><ul>
<li><code>flutter build</code>：命令默认会构建出release包</li>
<li><code>--split-per-abi</code>：表示构建单一架构</li>
</ul>
</div><div class="cl-preview-section"><h2 id="上传应用">上传应用</h2>
</div><div class="cl-preview-section"><p>安装包构建好之后发布到Android各大应用市场，无论是长传到那个应用市场首先需要注册该平台的开发者通过开发者认证后便可进行应用上传了。</p>
</div><div class="cl-preview-section"><p>开发者注册和应用上传各大平台都有详细的说明教程和问题，下面分享国内比较大的应用市场：</p>
</div><div class="cl-preview-section"><ul>
<li>华为：<a href="https://consumer.huawei.com/cn/">https://consumer.huawei.com/cn/</a></li>
<li>小米：<a href="https://dev.mi.com/console/">https://dev.mi.com/console/</a></li>
<li>OPPO：<a href="https://open.oppomobile.com/">https://open.oppomobile.com/</a></li>
<li>vivo：<a href="https://dev.vivo.com.cn/home">https://dev.vivo.com.cn/home</a></li>
<li>百度：<a href="https://app.baidu.com/apps/">https://app.baidu.com/apps/</a></li>
</ul>
</div><div class="cl-preview-section"><p>有需要的小伙伴可以按照官方的说明进行注册和上传应用。</p>
</div><div class="cl-preview-section"><h2 id="faq">FAQ</h2>
</div><div class="cl-preview-section"><h3 id="启用代码压缩后无法打包">启用代码压缩后无法打包</h3>
</div><div class="cl-preview-section"><p>很多同学会发现当启用代码压缩(minifyEnabled true )后，在打release包时报错，无法打出release包，那么只需将targetSdkVersion 和 compileSdkVersion 升级到 28。</p>
</div><div class="cl-preview-section"><blockquote>
<p>关联问题 @<a href="https://github.com/flutter/flutter/issues/26860#issuecomment-469751224">https://github.com/flutter/flutter/issues/26860#issuecomment-469751224</a></p>
</blockquote>
</div><div class="cl-preview-section"><h3 id="安装release包运行crash报so包找不到">安装release包运行crash报so包找不到</h3>
</div><div class="cl-preview-section"><p>flutter build apk只会打<code>armeabi-v7a</code>架构的flutter so，所以在release包前需要添加如下配置：</p>
</div><div class="cl-preview-section"><pre class=" language-bash"><code class="prism  language-bash">ndk <span class="token punctuation">{</span>
//            abiFilters <span class="token string">"armeabi-v7a"</span>,<span class="token string">"arm64-v8a"</span>,<span class="token string">"x86_64"</span>,<span class="token string">"x86"</span> //只打包flutter所支持的架构，flutter没有armeabi架构的so，加x86的原因是为了能够兼容模拟器
    abiFilters <span class="token string">"armeabi-v7a"</span> //release 时只打"armeabi-v7包
<span class="token punctuation">}</span>
</code></pre>
</div> <h1 style="color: red">认准一手，获取完整资料<br>QQ3195303913<br>微信wxywd8<br><br><br><br>高价回收正版课</h1></body></html>